package itheima.com.SocketTCPImg;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) throws Exception {

        ServerSocket serverSocket = new ServerSocket(8888);
        Socket accept = serverSocket.accept();
        System.out.println("服务端发送"+accept.getClass());


//        InputStream inputStream = accept.getInputStream();
        String filePath = "D:\\一条小团团\\filePath.jpg";
        BufferedInputStream bufferedInputStream = new BufferedInputStream(accept.getInputStream());
        byte[] bytes = StreamUtils.streamToByteArray(bufferedInputStream);

        System.out.println("拿到的bytes"+bytes);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(filePath));
        bufferedOutputStream.write(bytes);


//        bufferedOutputStream.close();
        bufferedOutputStream.close();
        bufferedInputStream.close();
        serverSocket.close();
        accept.close();


    }

}
